package uts.sdk.modules.ztUtsGdMap;

import com.bumptech.glide.Glide
import com.bumptech.glide.request.transition.Transition
import com.bumptech.glide.request.target.CustomTarget
import android.graphics.Bitmap
import android.content.Context
import android.graphics.drawable.Drawable

class ImageLoader(private val context: Context) {

    fun loadImage(url: String, addBitmapToMap: (Bitmap) -> Unit) {
        Glide.with(context)
            .asBitmap()
            .load(url)
            .into(MyCustomTarget { bitmap ->
                // 调用传入的 addBitmapToMap 回调
                addBitmapToMap(bitmap)
            })
    }
}

class MyCustomTarget(private val onResourceReady: (Bitmap) -> Unit) : CustomTarget<Bitmap>() {

    override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
        onResourceReady(resource)
    }

    override fun onLoadCleared(placeholder: Drawable?) {
        // 可以在这里处理加载清理的逻辑
    }
}
